package com.xieyingwangluo.yxpart.api;

import com.xieyingwangluo.yxpart.bean.Result;
import com.xieyingwangluo.yxpart.bean.UserComDTO;
import com.xieyingwangluo.yxpart.logic.UserComLogic;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: wangchaonan
 * @Date: 2018/10/8 9:55
 * @Version 1.0
 */
@Api(tags = "用户评论接口")
@Controller
@RequestMapping(value = "/api/v1/user_comment")
public class UserComBaseRest extends BaseRest {
    @Autowired
    private UserComLogic userComLogic;


    @ApiOperation(value = "添加用户评论", notes = "添加用户评论", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "user_id", value = "用户编号", required = true, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "star", value = "星级（非常差，差，一般，好，非常好）", required = true, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "info", value = "描述", required = false, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "part_id", value = "兼职编号", required = true, dataType = "String", paramType = "form")
    })
    @ResponseBody
    @PostMapping(value = "/add")
    public Result add(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                      UserComDTO userComDTO) {
        return userComLogic.add(userComDTO);
    }

    @ApiOperation(value = "修改用户评论", notes = "修改用户评论", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noid", value = "用户评论编号", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "user_id", value = "用户编号", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "star", value = "星级（非常差，差，一般，好，非常好）", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "info", value = "描述", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "part_id", value = "兼职编号", required = false, dataType = "String", paramType = "query")
    })
    @ResponseBody
    @PutMapping(value = "/upd")
    public Result update(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                         @RequestParam("noid") String noid,
                         UserComDTO userComDTO) {
        return userComLogic.upd(noid, userComDTO);
    }

    @ApiOperation(value = "显示用户评论", notes = "显示用户评论", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noid", value = "用户评论id", required = true, dataType = "String", paramType = "query")
    })
    @ResponseBody
    @GetMapping(value = "/selO")
    public Result selO(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                       @RequestParam("noid") String noid) {
        return userComLogic.getById(noid);
    }

    @ApiOperation(value = "模糊查询用户评论", notes = "模糊查询用户评论", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "user_id", value = "用户编号", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "star", value = "星级（非常差，差，一般，好，非常好）", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "info", value = "描述", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "part_id", value = "兼职编号", required = false, dataType = "String", paramType = "query")
    })
    @ResponseBody
    @PutMapping(value = "/selA")
    public Result selA(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                       UserComDTO userComDTO) {
        return userComLogic.selA(userComDTO);
    }

    @ApiOperation(value = "删除用户评论", notes = "删除用户评论", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noid", value = "用户评论id", required = true, dataType = "String", paramType = "query")
    })
    @ResponseBody
    @GetMapping(value = "/del")
    public Result del(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                      @RequestParam("noid") String noid) {
        return userComLogic.del(noid);
    }
}
